/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.arg.deploy.common;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

/**
 *
 * @author sorasaks
 */
public class ConvertFormatUtil {
    
    public final static String DEFAULT_DATE_FORMAT = "dd-MM-yyyy";
    public final static String DEFAULT_DATE_TIME_FORMAT = "dd/MM/yyyy hh:mm";
    public final static String DEFAULT_FULL_DATE_FORMAT = "dd MMMM yyyy";
    protected final static String DEFAULT_DATE_FORMAT_PERIOD = "yyyyMM";
    protected final static String DEFAULT_DATE_FORMAT_MONTH = "MMMM";
    protected final static String DEFAULT_NUMBER_FORMAT = "###0";
    protected final static String DEFAULT_DOUBLE_FORMAT = "#.######";
    public final static String DEFAULT_DECIMAL_0DIGIT_FORMAT = "#,##0";
    public final static String DEFAULT_DECIMAL_2DIGIT_FORMAT = "#,##0.00";
    protected final static String DEFAULT_NO_DATA = "-";
    
    public static String convertFormat(Date date) {
        return convertFormat(date, DEFAULT_DATE_FORMAT);
    }
    
    public static String convertFormat(String str) {
        return (str != null && str.trim().length() > 0) ? str.trim() : DEFAULT_NO_DATA;
    }
    
    public static String convertFormat(Date date, String format) {
        if (date == null) {
            return convertFormat((String) null);
        }

        SimpleDateFormat dateFormat = new SimpleDateFormat(format, Locale.US);
        try {
            return dateFormat.format(date);
        } catch (Exception e) {
            return convertFormat(date);
        }
    }

    public static String convertFormat(Date date, String format, Locale _locale) {
        if (date == null) {
            return convertFormat((String) null);
        }

        SimpleDateFormat dateFormat = new SimpleDateFormat(format, _locale);
        try {
            return dateFormat.format(date);
        } catch (Exception e) {
            return convertFormat(date);
        }
    }
}
